<template>
<uni-popup ref="showNum" type="dialog" :is-mask-click='false' :isBlur='true' mask-background-color="#0005">
	<view class="xx_div" >
		<image class="xx_top_bg" src="https://guizhou-oss.oss-cn-guiyang-gzdata-d01-a.res.gzdata.com.cn/ymt_new/my/hy_bg.png" mode="widthFix"></image>
		<view class="main_div">
			<view class="xx_title">
				您当前为免费用户
			</view>
			<view class="h20"></view>
			<view class="xx_desc" v-if='hasNum.remain_num>0'>
				您当前的身份可以查看{{hasNum.num}}次{{type_id==1?'企业':type_id==2?'图谱':type_id==3?'报告':type_id==4?'线索':type_id==5?'需求':''}}，目前还剩余<text>{{hasNum.remain_num}}</text>次，是否确定查看？
			</view>
			<view class="xx_desc" v-else>
				您当前查看次数已使用，您可以升级会员，继续查看
			</view>
			<view class="h30"></view>
			<view class="xx_btn_text" @click="toHy">加入会员查看更多></view>
			<view class="h46"></view>
			<view class="xx_btn" @click="sureNum">确 定</view>
		</view>
	</view>
</uni-popup>
</template>

<script>
import { getUserCurrentNums,sysUserUseLogs,checkUserUse }  from '@/utils/api.js'
export default {
	props:{
		type_id:{
			default:1
		},
		ra_id:{
			default:''
		}
	},
	data() {
		return {
			hasNum:{},
			type_name:''
		}
	},
	onShow(){
		if(uni.getStorageSync('token')){
			getUserCurrentNums().then(res=>{
				if(res.data[this.type_id].remain_num==-1){
					this.$refs.showNum.close()
				}
			})
		}
	},
	methods:{
		init(){
			if(!uni.getStorageSync('token')){
				let page = this.type_id==1?'companyDetail':
									 this.type_id==2?'chainDetail':
									 this.type_id==3?'reportDetail':
									 this.type_id==4?'xxDetail':''
									 this.type_id==5?'xsDetail':''
				let url = `/subPage/pages/login/login?page=${page}&id=${this.ra_id}`
				uni.redirectTo({
					url
				})
				return
			}else{
				checkUserUse({type_id:this.type_id,ra_id:this.ra_id}).then(res=>{
					if(res.status==0){
						getUserCurrentNums().then(res=>{
							this.hasNum = res.data[this.type_id-1]
							if(this.hasNum.remain_num>-1){
								this.$nextTick(()=>{
									this.$refs.showNum.open()
								})
							}
						})
					}
				})
			}
		},
		sureNum(){
			this.$refs.showNum.close()
			if(this.hasNum.remain_num==0){
				uni.navigateBack()
			}else{
				sysUserUseLogs({type_id:this.type_id,ra_id:this.ra_id})
			}
		},
		toHy(){
			if(!uni.getStorageSync('token')){
				uni.redirectTo({
					url:'/subPage/pages/login/login?type=huiyuan'
				})
			}else{
				uni.navigateTo({
					url:'/subPage/pages/huiyuan/huiyuan'
				})
			}
		},
	}
}
</script>

<style lang="scss" scoped>
.xx_div{
	width: 540rpx;
	border-radius: 20rpx;
	background: #fff;
	color: #333;
	font-size: 24rpx;
	padding: 50rpx 0 0;
	position: relative;
	.xx_top_bg{
		position: absolute;
		top:0;
		left:0;
		z-index:1;
		height: 370rpx;
		width:100%;
	}
	.main_div{
		position: relative;
		padding-top:225rpx;
		z-index:2;
		width:100%;
	}
	.xx_title{
		font-size: 30rpx;
		font-weight: 800;
		color: #333;
		text-align: center;
		margin-bottom: 30rpx;
	}
	.xx_close{
		position: absolute;
		right: 10rpx;
		top: 4rpx;
		width: 48rpx;
		height: 48rpx;
		image{
			width: 48rpx;
			height: 48rpx;
		}
	}
	.xx_desc{
		color: #666;
		// text-indent:48rpx;
		line-height: 40rpx;
		padding:0 60rpx;
		text{
			color:red
		}
	}
	.xx_btn_text{
		color:rgba(255, 47, 0, 1);
		font-size:32rpx;
		text-align: center;
	}
	.xx_btn{
		width: 100%;
		margin: 0 auto;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		border-top: 1rpx solid rgba(199, 199, 199, 1);
		color: rgba(153, 153, 153, 1);
		font-size: 28rpx;
	}
}
</style>
